package com.acxy.cms;

import com.acxy.ants.common.kit.PropKit;
import com.acxy.ants.core.Jetty;
import com.acxy.ants.core.annotation.Application;
import com.acxy.ants.core.config.*;
import com.acxy.ants.core.handler.PathHandler;
import com.acxy.ants.core.plugin.db.DruidPlugin;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 全局配置
 * @author MrShun
 * @version 1.0
 * @Date 2017-04-26
 */
@Application(scan = {"com.acxy.auth", "com.acxy.cms"})
public class AppConfig extends AntsConfig {



    /**
     * 常量配置
     *
     * @param me
     */
    @Override
    public void configConstant(Constants me) {
        PropKit.use("resources.properties");
        me.setDebug(PropKit.getBoolean("debug"));
        me.setError404Page("/error/404.html");
        me.setError500Page("/error/500.html");
    }

    /**
     * 插件配置
     *
     * @param me
     */
    @Override
    public void configPlugin(Plugins me) {
        me.add(new DruidPlugin(PropKit.getStr("url"), PropKit.getStr("driverClassName"), PropKit.getStr("username"), PropKit.getStr("password")));
    }

    /**
     * 拦截器配置
     *
     * @param me
     */
    @Override
    public void configInterceptor(Interceptors me) {

    }

    /**
     * handler请求链配置
     *
     * @param me
     */
    @Override
    public void configHandler(Handlers me) {
        Map<String, String> pathMap = new HashMap<>();
        pathMap.put("ctx", "");
        pathMap.put("JS_PATH", "/static/js");
        pathMap.put("IMG_PATH", "/static/images");
        pathMap.put("CSS_PATH", "/static/css");
        pathMap.put("SWF_PATH", "/static/swf");
        pathMap.put("UE_PATH", "/static/ueditor");
        me.add(new PathHandler(pathMap));
    }

    public static void main(String[] args) throws IOException {
        Jetty.start("ants-cms/src/main/webapp", 81, "/cms");
    }
}
